package com.baiwei.mapper;

import com.baiwei.pojo.Orders;
import com.baiwei.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user;")
    public List<User> findAll();
    //public List<User> findAllUserRole();
    @Select("select * from user where id=#{id};")
    public User findById(int id);
    @Insert(" insert into user values(#{id},#{username},#{password},#{birthday});")
    public int insert(User user);
    @Update(" update user set username=#{username},password=#{password},birthday=#{birthday} where id=#{id};")
    public int update(User user);
    @Delete(" delete from user where id=#{id};")
    public int delete(int id);
    @Select("select * from user;")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "username",column = "username"),
            @Result(property = "password",column = "password"),
            @Result(property = "birthday",column = "birthday"),
            @Result(property = "orders",column = "id",javaType = List.class,
            many = @Many(select = "com.baiwei.mapper.OrdersMapper.findByUid"))
})
    public List<User> findAllUserOrders();

    @Select("select * from user;")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "username",column = "username"),
            @Result(property = "password",column = "password"),
            @Result(property = "birthday",column = "birthday"),
            @Result(property = "roles",column = "id",javaType = List.class,
                    many = @Many(select = "com.baiwei.mapper.RoleMapper.findByUid"))
    })
    public List<User> findAllUserRole();
}
